package com.jams.goodox.activity.serve;

import android.content.Intent;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.entity.ServeSubmitBean;

import butterknife.Bind;
import butterknife.OnClick;
import uama.hangzhou.image.photochoose.FourPicturesChoose;

/**
 * 维修，报事，投诉表扬公用页面
 * Created by guozhen.hou on 2017/7/7.
 */

public abstract class BaseServeActivity extends BaseActivity {
    @Bind(R.id.order_homerepair_img1)
    ImageView orderHomerepairImg1;
    @Bind(R.id.order_homerepair_img2)
    ImageView orderHomerepairImg2;
    @Bind(R.id.order_homerepair_img3)
    ImageView orderHomerepairImg3;
    @Bind(R.id.order_homerepair_img4)
    ImageView orderHomerepairImg4;
    @Bind(R.id.linear_serve_head)
    LinearLayout linear_serve_head;
    @Bind(R.id.edit_describe)
    EditText editDescribe;

    private FourPicturesChoose fourPicturesChoose;
    private SparseArray<ImageView> viewSparseArray;
    protected String subId;

    @Override
    protected int getLayoutId() {
        return R.layout.base_serve_layout;
    }

    @Override
    protected void init() {
        viewSparseArray = new SparseArray<>();
        viewSparseArray.put(0,orderHomerepairImg1);
        viewSparseArray.put(1,orderHomerepairImg2);
        viewSparseArray.put(2,orderHomerepairImg3);
        viewSparseArray.put(3,orderHomerepairImg4);
        fourPicturesChoose = new FourPicturesChoose(this, viewSparseArray);
        subId = getIntent().getStringExtra("subId");
        initData();
    }

    /**
     * 请求服务暂停时间
     * 此处注意：维修不用于此请求服务暂停时间
     */
    protected void initStopTime(){
        ServeStopTime serveStopTime = new ServeStopTime(this);
        serveStopTime.init(subId);
    }

    /**
     * 获取页面标题
     * @return 标题
     */
    protected abstract String getBarTitle();

    /**
     * 提交表单服务
     */
    protected abstract void submitServeOrder();

    protected abstract void initData();

    /**
     * 用于判断编辑框是否填写了文案（已经过滤空格）
     * @return true 有文案 false无文案
     */
    protected boolean hasDescription(){
        return !TextUtils.isEmpty(editDescribe.getText().toString().trim());
    }

    protected void setEditHint(String hintText){
        editDescribe.setHint(hintText);
    }
    /**
     * 添加基础提交信息的页面
     * 1:描述信息
     * 2：图片
     * 3：服务id
     * 4：服务标题
     */
    protected ServeSubmitBean getSubmitWithBaseParams(){
        ServeSubmitBean serveSubmitBean=new ServeSubmitBean();
        serveSubmitBean.setMsg(editDescribe.getText().toString().trim());//描述文案
        serveSubmitBean.setPhotos(fourPicturesChoose.getChosenImageList());//图片列表
        serveSubmitBean.setSubId(subId);//服务id
        serveSubmitBean.setTitle(getBarTitle());//服务标题
        return serveSubmitBean;
    }

    /**
     * 用于给报事&投诉表扬添加head
     * @param view 待加入的控件
     */
    protected void addServeHeadView(View view){
        linear_serve_head.removeAllViews();
        linear_serve_head.addView(view);
    }

    @OnClick(R.id.tx_submit)
    public void onViewClicked() {
        submitServeOrder();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        fourPicturesChoose.setImageList(requestCode, resultCode, data);
    }
}
